package org.eclipse.unofficial.flexitabs;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.unofficial.flexitabs.adapted.FlexiPart;
import org.eclipse.unofficial.flexitabs.adapted.FlexiPartSashContainer;
import org.eclipse.unofficial.flexitabs.internal.WorkbenchPage;



public class FlexiTabContainer extends Composite {
	private WorkbenchPage page;
	private FlexiPartSashContainer container;
	
	public FlexiTabContainer(Composite parent) {		
		super(parent, SWT.NONE);
		this.setLayout(new FillLayout());
		
		page = new WorkbenchPage(this);
		container = new FlexiPartSashContainer("UNUSED_ID", page, this);
		page.setContainer(container);
		container.createControl(this);
		container.setVisible(true);
		container.setActive(true);
		
//		parent.addListener(SWT.Dispose, new Listener() {
//			@Override
//			public void handleEvent(Event event) {
//				container.setActive(false);
//			}
//		});
	}

	public FlexiTab addTab(FlexiTabClient client) {
		FlexiTab tab = new FlexiTab(client, page);
		container.add(tab.getPane());
		tab.getPane().setVisible(true);
		return tab;
	}

	public void setFocusTab(FlexiTab tab) {
		page.requestActivation(tab.getPart(false));
	}

	public FlexiTab getFocusTab() {
		return ((FlexiPart) page.getActivePart()).getTab();
	}

	public void deactivate() {
		container.dispose();
//		container.setActive(false);
	}
}
